<?php 

class Page{
	private $totalPage;//总页数
	private $selfPage;//当前页数
	private $row;//每页显示的条数
	private $url;//获得当前的url
	public function __construct($total,$row=15)
	{
		$this->row=$row;
		$this->totalPage=ceil($total/$row);
		$this->selfPage=isset($_GET['page'])?min(intval($_GET['page']),$this->totalPage):1;  //intval取变量整数值
		$this->url=$this->getUrl();
	}

	private function getUrl()
	{
		if(isset($_GET['page']))unset($_GET['page']);
		$url=__WEB__.'?';
		foreach ($_GET as $key => $value) {
			$url.="$key=$value"."&";
		}
		$url.='page=';
		return $url;
	}

	//返回sql需要的limit
	public function limit()
	{
		return ($this->selfPage-1)*$this->row.','.$this->row;//////limit 0,2
	}
	//显示页数
	public function show($value='')
	{
		$html='';
		for ($i=1; $i <=$this->totalPage; $i++) { 
			if ($i==$this->selfPage) {
				$html.="<strong>$i</strong>";
			}else{
				$url=$this->url.$i;
				$html.="<a href='{$url}'>$i</a>";
			}
		}
		return $html;
	}
}

 ?>